package com.bingo.generate.cli;


import com.bingo.generate.cli.Cmds.ExitCmd;
import com.bingo.generate.cli.Cmds.GenerateDbCmd;
import com.bingo.generate.comm.util.PathUtils;
import org.apache.commons.lang3.StringUtils;
import picocli.CommandLine;

import java.nio.file.Paths;
import java.util.Scanner;

public class Use {

    public static void main(String[] args) {
        PathUtils.cofDir= Paths.get("C:\\temp\\gererate-path");
        useCli();
    }

    public static void useCli() {
        if(PathUtils.cofDir==null){
            throw new RuntimeException("请在代码中或者启动参数中加入配置文件目录的信息");
        }
        Scanner sc= OldUse.sc;
        CommandLine commandLine = new CommandLine(new GenerateRootCommand());
        while (true) {
            System.out.println("欢迎来到main界面 -请输入你的命令(可以通过输入-h 查询命令):");
            String str = sc.nextLine();
            //  去除空格
            str = StringUtils.trim(str);
            //  如果是null，就重新弄一下
            if (StringUtils.isBlank(str)) {
                System.out.println("");
                System.out.println("请输入~~~");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                continue;
            }
            String[] args=str.split(" ");
            commandLine.execute(args);
        }
    }

    // 将所有子命令装载在一起
    @CommandLine.Command(name = "generate-cli",
            subcommands = {
                    // command1
                    ExitCmd.class,
                    // command2
                    GenerateDbCmd.class
                    // 添加 yourCommand.class
            },
            mixinStandardHelpOptions = true
    )
    public static class GenerateRootCommand{

    }

}
